//
//  SchoolViewModel.m
//  BOSS-SOOC
//
//  Created by apple on 16/8/12.
//  Copyright © 2016年 Gcx. All rights reserved.
//

#import "SchoolViewModel.h"
#import "PlayerViewController.h"
#import "SchoolModel.h"
#import "BannerModel.h"

@implementation SchoolViewModel

- (id)init{

    if (self = [super init]) {
        
        _sourceArr = [NSMutableArray array];
    }
    return self;
}

- (void)getSchoolDatePage:(long)page{
    
    NSDictionary *dic = @{@"oauth_token":@"815bffb68e2ea44e38cf16a98a5a29a4",@"oauth_token_secret":@"8e84bc64f03d73b5c75406ef1d7349f7",@"page":[NSString stringWithFormat:@"%ld",page],@"pageCount":@10};

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:dic];
    
    SCHttpRequest *request = [[SCHttpRequest alloc]initWithApi:API_allNewCourse params:params];
    
    [self doPOSTConnect:request start:^(SCHttpRequest * _Nonnull req) {
        
    } success:^(SCHttpRequest * _Nonnull req, SCHttpResponse * _Nonnull resp) {

        NSArray *subjects = resp.originalDictionary[@"data"];
        
        
        /**
         *  第一页清空所有数据
         */
        if (page == 1) {
            
            [_sourceArr removeAllObjects];
        }
        
        for (NSDictionary *tempDic in subjects) {
            
            SchoolModel *model = [SchoolModel modelWithDic:tempDic];

            [_sourceArr addObject:model];
        }
        
        _succeedBlock(_sourceArr);
        
    } failure:^(SCHttpRequest * _Nonnull req, NSError * _Nonnull error) {
        
        _failBlock(error);
        

    } finish:^(SCHttpRequest * _Nonnull req, BOOL success) {
        
        [[NSNotificationCenter defaultCenter]postNotificationName:@"isRefresh" object:nil];

    }];

}

- (void)getBannerDate{

    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    SCHttpRequest * request = [[SCHttpRequest alloc]initWithApi:API_lunboImage params:params];
    
    [self doPOSTConnect:request start:^(SCHttpRequest * _Nonnull req) {
        
    } success:^(SCHttpRequest * _Nonnull req, SCHttpResponse * _Nonnull resp) {
        
        NSArray *subjects = resp.originalDictionary[@"data"];
        
        NSMutableArray *modelArr = [NSMutableArray arrayWithCapacity:subjects.count];
        
        for (NSDictionary *tempDic in subjects) {
            
            BannerModel *model = [BannerModel modelWithDic:tempDic];
            
            [modelArr addObject:model];
        }
        
        _succeedBannerBlock(modelArr);
        
    } failure:^(SCHttpRequest * _Nonnull req, NSError * _Nonnull error) {
        
        _FailBannerBlock(error);
        
    } finish:^(SCHttpRequest * _Nonnull req, BOOL success) {
        
    }];
}

- (void)schoolDetailWithSchoolModel:(SchoolModel *)shcoolModel WithViewController:(UIViewController *)superController{
    
    PlayerViewController *detail = [[PlayerViewController alloc]init];
    detail.hidesBottomBarWhenPushed = YES;
    [superController.navigationController pushViewController:detail animated:YES];
}


@end
